package com.example.blogdemo.controller;

import com.example.blogdemo.mapper.BlogMapper;
import com.example.blogdemo.pojo.request.UserRequest;
import com.example.blogdemo.pojo.respond.GetUserInfo;
import com.example.blogdemo.pojo.respond.UserRespond;
import com.example.blogdemo.service.BlogService;
import com.example.blogdemo.service.UserService;
import com.example.blogdemo.service.impl.BlogServiceImpl;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Scanner;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Resource(name = "userServiceImpl")
    private UserService userService;
    @Autowired
    private BlogMapper blogMapper;
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;

    @RequestMapping("/login")
    public UserRespond login(@RequestBody @Validated UserRequest userRequest) {

        log.info("用户名，p:{}", userRequest.getUserName());
        return userService.login(userRequest);
    }

    @RequestMapping("/getUserInfo")
    public GetUserInfo getUserInfof(@NotNull(message = "userId 不能为空") Integer userId) {
        log.info("userId:{}", userId);
        return userService.getUserInfo(userId);
    }

    @RequestMapping("/getAuthorInfo")
    public GetUserInfo getAuthorInfo(@NotNull(message = "blogId 不能为空") Integer blogId) {
        log.info("blogId:{}", blogId);

        return userService.getAuthorInof(blogId);
    }


}
